package com.ming_za.odupdaterserver.core.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import org.springframework.stereotype.Component;

@Component
public class JsonUtils {

    private final ObjectMapper mapper = new ObjectMapper();

    @Getter
    private static JsonUtils instance;

    public JsonUtils() {
        instance = this;
    }

    public <T> T fromJson(String json, Class<T> classOfT) throws JsonProcessingException {
        return mapper.readValue(json,classOfT);
    }

    public String toJson(Object obj) throws JsonProcessingException {
        return mapper.writeValueAsString(obj);
    }
}
